home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / REDIRECT.SWG / 0007_Redirect output.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  1KB  |  88 lines

  1. { From: tjacobs@clark.net (Todd A. Jacobs) }
  2. unit Redir;
  3.  
  4. interface
  5.  
  6. uses
  7.   Dos;
  8.  
  9. function SetOutput(FileName: PathStr): Boolean;
  10. procedure CancelOutput;
  11.  
  12. implementation
  13.  
  14. const
  15.   OutRedir: Boolean = False;
  16.  
  17. function SetOutput(FileName: PathStr): Boolean;
  18. begin
  19.   FileName:=FileName+#0;
  20.   SetOutput:=False;
  21.   asm
  22.     push  ds
  23.     mov   ax, ss
  24.     mov   ds, ax
  25.     lea   dx, FileName[1]
  26.     mov   ah, 3Ch
  27.     int   21h
  28.     pop   ds
  29.     jnc   @@1
  30.     ret
  31. @@1:
  32.     push  ax
  33.     mov   bx, ax
  34.     mov   cx, Output.FileRec.Handle
  35.     mov   ah, 46h
  36.     int   21h
  37.     mov   ah, 3Eh
  38.     pop   bx
  39.     jnc   @@2
  40.     ret
  41. @@2:
  42.     int   21h
  43.   end;
  44.   OutRedir:=True;
  45.   SetOutput:=True;
  46. end;
  47.  
  48. procedure CancelOutput;
  49. var
  50.   FileName: String[4];
  51. begin
  52.   if not OutRedir then Exit;
  53.   FileName:='CON'#0;
  54.   asm
  55.     push  ds
  56.     mov   ax, ss
  57.     mov   ds, ax
  58.     lea   dx, FileName[1]
  59.     mov   ax, 3D01h
  60.     int   21h
  61.     pop   ds
  62.     jnc   @@1
  63.     ret
  64. @@1:
  65.     push  ax
  66.     mov   bx, ax
  67.     mov   cx, Output.FileRec.Handle
  68.     mov   ah, 46h
  69.     int   21h
  70.     mov   ah, 3Eh
  71.     pop   bx
  72.     int   21h
  73.   end;
  74.   OutRedir:=False;
  75. end;
  76.  
  77. end.
  78. {
  79. Standard output will be changed to FileName. The FileName can be NUL.
  80. When your
  81. executed program is using int $10, all is hardly. In your main program use:
  82.  
  83. SetOutput('NUL');
  84. Exec(....);
  85. CancelOutput;
  86. }
  87.  
  88.